import common from '@/mixins/common.js'
export default {
  name: 'changeParkPayMerchantAccount',
  mixins: [common],

  data () {
    return {
      merchantList: [],
      selectedMerchant: '',
      query: {}
    }
  },

  created () {
    this.query = this.$route.query
    this.getOperatorPayMerchantInfo()
  },

  methods: {
    // 根据运营商id获取支付商户配置
    getOperatorPayMerchantInfo () {
      let self = this
      this.selectedMerchant = Number(this.query.merchantId)
      let params = {
        operatorId: sessionStorage.getItem('_operatorID')
      }
      API.fetchGet('/valueAdded/getOperatorPayMerchantInfo', params)
        .then(data => {
          console.log(data)
          self.merchantList = data || []
        }, err => {
          self.merchantList = []
        })
    },

    changeParkPayMerchantAccount () {
      let self = this
      if (this.selectedMerchant === Number(this.query.merchantId)) {
        this.showToast('账号未更改！', 2, 2000)
        return
      }
      let params = {
        merchantId: this.selectedMerchant,
        parkId: this.query.parkId,
        payPlatform: this.query.payPlatform
      }

      API.fetchPost('/valueAdded/changeParkPayMerchantAccount', params)
        .then(data => {
          // console.log(data)
          self.showToast('更改账号成功！', 1, 1500)
          self.closePage(1000)
        }, err => {
          self.showToast('更改账号失败！', 2, 1500)
        })

    }
  }
}
